package org.goodsl.mdd.validator;

import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.goodsl.mdd.Seg;


import org.goodsl.mdd.SingleValidResult;

import org.goodsl.mdd.Validator;

/**
 * Created with IntelliJ IDEA.
 * User: Simon Xiao
 * Date: 12-11-14
 * Time: 上午8:47
 * To change this template use File | Settings | File Templates.
 */
public class AssertTrueValidator extends Validator<Seg> {
    public AssertTrueValidator(String message) {
         super(message);

     }

     @Override
     public SingleValidResult<Seg> verify(Seg variable) {

         Object value = variable.getValue();
         if (DefaultTypeTransformation.castToBoolean(value))
             return new SingleValidResult<Seg>(true, "", variable, this);
         else
             return new SingleValidResult<Seg>(false, getMessage(), variable, this);
     }

}
